<template>
	<view @click="toInformation" class="bg-white flex-row"
		style="height: 50px;width: 100%;margin-top: 10px;justify-content: space-between;">
		<view style="height: 100%;display: flex;align-items: center;margin-left: 15px;">
			个人信息
		</view>
		<view style="margin-top: 15px;">
			<uni-icons type="right" size="20" color="#8E8E8E"></uni-icons>
		</view>
	</view>
	<view @click="tovolunt" class="bg-white flex-row"
		style="height: 50px;width: 100%;margin-top: 2px;justify-content: space-between;">
		<view style="height: 100%;display: flex;align-items: center;margin-left: 15px;">
			志愿者信息
		</view>
		<view style="margin-top: 15px;">
			<uni-icons type="right" size="20" color="#8E8E8E"></uni-icons>
		</view>
	</view>
	<view @click="to_privacy(3)" class="bg-white flex-row"
		style="height: 50px;width: 100%;margin-top: 2px;justify-content: space-between;">
		<view style="height: 100%;display: flex;align-items: center;margin-left: 15px;">
			隐私政策
		</view>
		<view style="margin-top: 15px;">
			<uni-icons type="right" size="20" color="#8E8E8E"></uni-icons>
		</view>
	</view>
	<view class="bg-white flex-row" style="height: 50px;width: 100%;margin-top: 2px;justify-content: space-between;" @click="gittoweb">
		<view style="height: 100%;display: flex;align-items: center;margin-left: 15px;">
			关于我们
		</view>
		<view style="margin-top: 15px;">
			<uni-icons type="right" size="20" color="#8E8E8E"></uni-icons>
		</view>
	</view>
	<!-- <view class="bg-white flex-row" style="height: 50px;width: 100%;margin-top: 2px;justify-content: space-between;">
		<view style="height: 100%;display: flex;align-items: center;margin-left: 15px;">
			申请注销
		</view>
		<view style="margin-top: 15px;">
			<uni-icons type="right" size="20" color="#8E8E8E"></uni-icons>
		</view>
	</view> -->
	<view @click="tohuens" class="bg-white flex-row"
		style="height: 50px;width: 100%;margin-top: 2px;justify-content: space-between;">
		<view style="height: 100%;display: flex;align-items: center;margin-left: 15px;">
			问题反馈
		</view>
		<view style="margin-top: 15px;">
			<uni-icons type="right" size="20" color="#8E8E8E"></uni-icons>
		</view>
	</view>
	<view class="bg-white flex-row" style="height: 50px;width: 100%;margin-top: 10px;justify-content: space-between;">
		<view @click="onLogin"
			style="height: 100%;display: flex;align-items: center;justify-content: center;width: 100%;color: red;">
			退出登录
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref, reactive } from 'vue';
	import { onShow, onReady } from "@dcloudio/uni-app"
	import { userinfo } from '../../api/myhome/login';
	import { imgURL2, imgURL3 } from '../../api/request'
	let form = reactive({
		value: {
			nickName: '未登陆',
			text: '这个人很懒，什么都没说',
			integral: 1299,
			time: '2024-4-23',
			workhours: 568,
			role: 0,
			realNameAuthenticated: 0
		}
	});


	//选择器
	const service = ref([
		['移动', '联通', '电信']
	])

	//运营商
	const service_name = ref('')

	const picker = ref(null)

	onReady(() => {
		if (uni.getStorageSync('service_name')) {
			service_name.value = uni.getStorageSync('service_name')
		} else {
			picker.value.open();
		}
	})

	onShow(() => {
		userinfo().then(res => {
			console.log('获取用户信息成功' + JSON.stringify(res.data));
			form.value = res.data; // 在数据完全加载后更新页面数据
			form.value.nickName = form.value.nickName.slice(0, 8)
		})


	})
	// 跳转到关于我们
	const gittoweb = ()=>{
		uni.navigateTo({
			url:'/pages/me/aboutUs'
		})
	}
	//跳转隐私协议
	const to_privacy = (e) => {
		uni.navigateTo({
			url: '/pages/agreement/index?e=' + e
		})
	}
	const toInformation = () => {
		uni.navigateTo({
			url: '/pages/me/informationMe'
		})
	}
	const tovolunt = () => {
		if (form.value.role == 0) {
			uni.showToast({
				title: '请先加入志愿者',
				icon: 'none',
				duration: 2000
			})
		} else {
			uni.navigateTo({
				url: '/pages/me/Voluntinform'
			})


		}

	}
	const tohuens = () => {
		// 问题反馈
		uni.navigateTo({
			url: '/pages/me/feedback'
		})
	}
	const service_confirm = (e) => {
		console.log('confirm', e);
		service_name.value = e.value[0]
		uni.setStorageSync('service_name', service_name.value)
	}

	const onLogin = () => {
		uni.removeStorageSync('token')
		uni.redirectTo({
			url: '/pages/login/login'
		})
	}
	const handleSelect = () => {
		uni.chooseImage({
			success: (chooseImageRes) => {
				const tempFilePaths = chooseImageRes.tempFilePaths;
				uni.uploadFile({
					url: 'https://api.anred.qrsk.net/applet/user/avatar', //仅为示例，非真实的接口地址
					header: { 'Authorization': uni.getStorageSync('token') },
					filePath: tempFilePaths[0],
					name: 'file',
					formData: {
						'user': 'test'
					},
					success: (uploadFileRes) => {
						form.value.avatarUrl = JSON.parse(uploadFileRes.data).data
						uni.showToast({
							title: "头像更换成功"
						})
						console.log(JSON.parse(uploadFileRes.data), "我是恋爱脑");
					}
				});
			}
		});
	}
</script>

<style>
	page {
		background-color: #EFEFEF;
	}
</style>